import React, { Component } from 'react'
import {ListBox} from '../../../components'
import UpdateWorkareaPage from './UpdateNew'
import UpdateWorkareaPageUp from './UpdateNewUp'

import {fetchData} from '../../../components/AjaxConsumer'
import {  Button, Modal, Form, Input, Radio,Upload, Icon } from 'antd';
export default class ListRawStorageSnPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
            
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'export',
                showName: 'Excel',
                iconClass: 'file-excel'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'storageSnId',
            data: [
                {
                    showName: 'storageSnId',
                    columnName: 'storageSnId',
                    columnHidden:true,
                    foreverHidden: true
                },{
                    showName: '合同编号',
                    columnName: 'contractNo',
                    columnWidth: 120
                },
                {
                    showName: '型号代码',
                    columnName: 'model'
                },
                {
                    showName: '型号类型',
                    columnName: 'modelType'
                },
                {
                    showName: '型号描述',
                    columnName: 'modelDesc'
                },{
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth: 120
                },{
                    showName: '单位',
                    columnName: 'unit'
                },
                {
                    showName: '数量',
                    columnName: 'amount'
                },  {
                    showName: '状态',
                    columnName: 'barcodeStatus',
                    showOption: [//页面显示配置
                        {
                            optionKey: '0',
                            optionShow: '可用'
                        }, {
                            optionKey: '1',
                            optionShow: '冻结'
                        }, {
                            optionKey: '2',
                            optionShow: '已出库'
                        }, {
                            optionKey: '3',
                            optionShow: '报废'
                        }
                    ]
                }, {
                    showName: '创建时间',
                    columnName: 'gmtCreate',
                    columnWidth: 140
                }, {
                    showName: '创建人',
                    columnName: 'createBy',
                    columnWidth: 80
                }
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '状态',
                name: 'barcodeStatus',
                type: 'select',
                optionList: [//下拉框的信息
                    //下拉框的信息
                    {
                        optionKey: '',
                        optionShow: ''
                    },{
                        optionKey: '0',
                        optionShow: '可用'
                    }, {
                        optionKey: '1',
                        optionShow: '冻结'
                    }, {
                        optionKey: '2',
                        optionShow: '已出库'
                    }, {
                        optionKey: '3',
                        optionShow: '报废'
                    }
                ]
            },
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList: [//下拉框的信息
                ]
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax',
                minName:'gmtModifiedMin'
            }
        ];

    }

    rowHandles = (strHandles, rowObj) => {
        if (strHandles == 'export') {
            this.exportXlsHandle(rowObj);
        }
    }
    exportXlsHandle = (conditonData) => {
        console.log('-------导出条件--------', conditonData);
        let param = '?'
        for (let key in conditonData) {
            if (conditonData[key] != '') {
                console.log(key, conditonData[key]);
                param = param + key + '=' + conditonData[key] + '&'
            }
        }
        console.log(param);
        window.location.href = '/material/intowarehouse/barcode/listIntoWhExp' + param;
    }


    //刷新列表
    refreshHandle = () => {
        this.refs.listWorkarea.refreshHandle();
    }

    componentWillMount() {
        const dicType = 'model_type';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[3].showOption = optionList;
        this.searchComponentData[1].optionList = optionList;
        //this.setState({
        //    tableColumn: this.tableColumn,
        //    searchComponentData: this.searchComponentData
        //})

    }

  handleCancel = () => {
    this.setState({ visible: false });
      this.form.resetFields();
    
  }
  handleCreate = () => {
    const form = this.form;
    form.validateFields((err, values) => {
      if (err) {
        return;
      }

      console.log('Received values of form: ', values);
      form.resetFields();
      this.setState({ visible: false });
    });
  }
  saveFormRef = (form) => {
    this.form = form;
  }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listWorkarea'
                    title="原材料入库明细"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/material/intowarehouse/barcode/intowh/list'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle = "true"
                />

                <UpdateWorkareaPage
                    ref="updateWorkarea"
                    refreshHandle={this.refreshHandle}
                />
                 <UpdateWorkareaPageUp
                    ref="updateWorkareaUp"
                    refreshHandle={this.refreshHandle}
                /> 
            
            </div>
        )
    }
}
